
//Basic string compression:
//aabccccaaa ->a2b1c5a3
public class q5 {

	public static void main(String args[]){
		System.out.println(compression("aaaaaaaaaaaaaaggvsrbeb"));
		
		
	}
	public static String compression(String input){
		if(input.length() <= 1){
			return input;
		}
		String result = "";
		char previous = input.charAt(0);
		int counter = 1;
		for(int i = 1; i< input.length(); i++){
			if(input.charAt(i) == previous){
				counter++;
			}else{
				result += previous + "" + counter;
				counter = 1;
				previous = input.charAt(i);
			}
		}
		result += previous+"" + counter + "";
		if(input.length() > result.length()){
			return result;
		}else{
			return input;
		}
	}
	
}
